<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="/WEB-INF/webpage/common/taglibs.jspf"%>
<!DOCTYPE html>
<html>
<head>
    <title>冷藏车关联</title>
    <meta name="decorator" content="form"/>
    <html:css name="bootstrap-fileinput" />
    <html:css name="simditor,jqgrid" />
</head>

<body class="white-bg">
		<table class="table table-bordered  table-condensed dataTables-example dataTable no-footer">
		   <tbody>
				<tr>
					<td  class="width-15 active text-right">
						<label><font color="red">*</font>冷藏车:</label>
					</td>
					<td class="width-35">
						<input id="ccZcdCarRelationCarid" class="form-control" datatype="*" nullmsg="请选择冷藏车编号！" htmlEscape="false" readonly="readonly" value="${car}"/>
						<label class="Validform_checktip"></label>
					</td>
					<td class="width-15 active text-right">
						<label><font color="red">*</font>冷藏车测点1:</label>
					</td>
					<td class="width-35" >
						<input id="ccZcdCarRelationMeasurepointOne" class="form-control" datatype="*" nullmsg="请选择冷藏车测点1！" htmlEscape="false" readonly="readonly" value="${pointOne}"/>
						<label class="Validform_checktip"></label>
					</td>
				</tr>
				<tr>
					<td  class="width-15 active text-right">
						<label><font color="red">*</font>冷藏车测点2:</label>
					</td>
					<td class="width-35">
						<input id="ccZcdCarRelationMeasurepointTwo" class="form-control" datatype="*" nullmsg="请选择冷藏车测点2！" htmlEscape="false" readonly="readonly" value="${pointTwo}"/>
						<label class="Validform_checktip"></label>
					</td>
					<td class="width-15 active text-right">
					</td>
					<td class="width-35" >
					</td>
				</tr>
		   </tbody>
		</table>   
	<div class="row">
        <div class="tabs-container">
            <ul class="nav nav-tabs">
            	<li class="active"><a data-toggle="tab" href="#tab_ccZcdMxCarRelation" aria-expanded="true">装车单明细</a></li>
            </ul>
            <div class="tab-content">
                 <div id="tab_ccZcdMxCarRelation" class="tab-pane active">
                    <div class="panel-body">
                        <grid:grid id="ccZcdMxCarRelationGridId" datas="${zcdMxList}" pageable="false" shrinkToFit="false" multiselect="false">
							<grid:column label="cc.zcdHz.zhuangcdNo" name="zhuangcdNo" width="120"/>
							<grid:column label="cc.zcdMx.zhuangcdId" name="zhuangcdId" width="140"/>
							<grid:column label="cc.zcdMx.liushBarcode" name="liushBarcode"/>
							<grid:column label="cc.zcdMx.ywbm" name="ywbm" width="80"/>
							<grid:column label="cc.zcdMx.danjNo" name="danjNo" width="110"/>
							<grid:column label="cc.zcdMx.shangpNo" name="shangpNo" width="100"/>
							<grid:column label="cc.zcdMx.chineseName" name="chineseName" />
							<grid:column label="cc.zcdMx.tongyName" name="tongyName" width="80"/>
							<grid:column label="cc.zcdMx.shijJs" name="shijJs" width="60"/>
							<grid:column label="cc.zcdMx.shijLss" name="shijLss" width="60"/>
							<grid:column label="cc.zcdMx.shijNum" name="shijNum" width="60"/>
							<grid:column label="cc.zcdMx.baozNum" name="baozNum" width="60"/>
							<grid:column label="cc.zcdMx.lot" name="lot" width="100"/>
							<grid:column label="cc.zcdMx.youxDate" name="youxDate" />
							<grid:column label="cc.zcdMx.wendMin" name="wendMin" />
							<grid:column label="cc.zcdMx.wendMax" name="wendMax" />
							<grid:column label="cc.zcdMx.danwName" name="danwName"/>
							<grid:column label="cc.zcdMx.address" name="address"/>
						</grid:grid>
					</div>
                </div>
            </div>
        </div>
    </div>
<html:js name="bootstrap-fileinput" />
<html:js name="simditor,jqgrid,jqGrid_curdtools,jqGrid_curdtools_inline" />
<script>
	$(document).ready(function () {
	    $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
	    	 resizeGrid();
		});

		// 冷藏车
		$('#ccZcdCarRelationCarid').click(function() {
			openDialogSetValueForTxt('冷藏车关联', '${adminPath}/cc/zcd/mx/chillCarList?zhuangcdNos=${zhuangcdNos}', 'ccZcdMxChillCarGridIdGrid', '1000px', '500px', 'id,measurepointOne,measurepointTwo', 'ccZcdCarRelationCarid,ccZcdCarRelationMeasurepointOne,ccZcdCarRelationMeasurepointTwo')
		});

		// 冷藏车测点1对应的采集温度设备
		$('#ccZcdCarRelationMeasurepointOne').click(function() {
			openDialogSetValueForTxt('设备关联', '${adminPath}/cc/zcd/mx/deviceList?zhuangcdNos=${zhuangcdNos}', 'ccZcdMxDeviceGridIdGrid', '1000px', '500px', 'id', 'ccZcdCarRelationMeasurepointOne')
		});

		// 冷藏车测点2对应的温度采集设备
		$('#ccZcdCarRelationMeasurepointTwo').click(function() {
			openDialogSetValueForTxt('设备关联', '${adminPath}/cc/zcd/mx/deviceList?zhuangcdNos=${zhuangcdNos}', 'ccZcdMxDeviceGridIdGrid', '1000px', '500px', 'id', 'ccZcdCarRelationMeasurepointTwo')
		});
	});
	$(function(){
	   $(window).resize(function(){   
		   resizeGrid();
	   });
	});

	function resizeGrid(){
		 $("#ccZcdMxCarRelationGridId").setGridWidth($(window).width()-60);
	}

	/* 父页面点击确定时触发的事件 */
	function confirm(callback) {
		// 判断是否已经选择了冷藏车以及测点，测点必须是不同的设备
		var chillCarId = $('#ccZcdCarRelationCarid').val();
		var measurepointOne = $('#ccZcdCarRelationMeasurepointOne').val();
		var measurepointTwo = $('#ccZcdCarRelationMeasurepointTwo').val();
		if (isNull(chillCarId) || isNull(measurepointOne) || isNull(measurepointTwo)) {
			top.layer.alert('请选择对应的冷藏车，以及测点1和测点2对应的温度采集设备!', {icon: 0, title:'警告'});
			return;
		}
		if (measurepointOne == measurepointTwo) {
			top.layer.alert('测点1和测点2必须使用不同的温度采集设备!', {icon: 0, title:'警告'});
			return;
		}

		// 判断冷藏车将要关联的装车单是否商品存储温度一致
		var rowsData = $("#ccZcdMxCarRelationGridIdGrid").jqGrid('getRowData');
		// 判断一个流水号是否关联了多个设备以及保温箱
		for (var i = 0; i < rowsData.length; i++) {
			for (var j = 0; j < rowsData.length; j++) {
				// 判断本次关联中是否存在一个保温箱下是否存在温度范围不同的商品
				if (rowsData[i].wendMin != rowsData[j].wendMin || rowsData[i].wendMax != rowsData[j].wendMax) {
					top.layer.alert('冷藏车' + chillCarId + '内存在温度储存范围不同的商品', {icon: 0, title:'警告'});
					return;
				}
			}
		}

		// POST请求配送交接
		$.ajax({
			type: "POST",
			url: "${adminPath}/cc/zcd/carRelation",
			data: {
				zhuangcdNos : '${zhuangcdNos }',
				chillCarId : chillCarId,
				measurepointOne : measurepointOne,
				measurepointTwo : measurepointTwo
			},
			traditional: true,
			success: function (data) {
				top.layer.alert(data.msg, {icon: 0, title:'提示'});
				if (data.ret == 0) {
					// 最后调用回调函数，关闭对话框
					if (typeof callback == "function") {
						callback();
					}
				}
			}
		});
	}

</script>
</body>
</html>